require 'test/unit'
require 'two_d'

class TwoDTest < Test::Unit::TestCase
 
  def test_single_term
    test_array = [ ["   "," 1"," 2"," 3"," 4"," 5"," 6"," 7"," 8"],
                   [" 1 "," -"," -"," -"," -","  ",:moo,"  "," -"],
                   [" 2 "," -"," C",:moo," -"," -"," -"," -"," -"],
                   [" 3 ",10  ," -"," -"," -",  10," -"," -"," -"],
                   [" 4 "," -"," -",:moo," -"," -"," -"," -"," -"],
                   [" 5 "," -"," -"," -"," X"," -"," -","  "," -"],  
                   [" 6 ","  "," -",  10," -"," -"," -","  "," -"],  
                   [" 7 "," C"," -"," -"," -"," C"," -"," -"," -"],  
                   [" 8 "," -"," -"," -"," -"," -"," -"," -"," -"] 
                 ]
    expected_result = {" C"=>[[2, 2], [7, 1], [7, 5]]}
    actual_result   = two_d(test_array, " C")
    assert_equal expected_result, actual_result
  end

  def test_multiple_terms
    test_array = [ ["   "," 1"," 2"," 3"," 4"," 5"," 6"," 7"," 8"],
                   [" 1 "," -"," -"," -"," -","  ",:moo,"  "," -"],
                   [" 2 "," -"," C",:moo," -"," -"," -"," -"," -"],
                   [" 3 ",  9 ," -"," -"," -",   9," -"," -"," -"],
                   [" 4 "," -"," -",:moo," -"," -"," -"," -"," -"],
                   [" 5 "," -"," -"," -"," X"," -"," -","  "," -"],  
                   [" 6 "," -"," -",   9," -"," -"," -","  "," -"],  
                   [" 7 "," C"," -"," -"," -"," C"," -"," -"," -"],  
                   [" 8 "," -"," -"," -"," -"," -"," -"," -"," -"] 
                 ]
    terms           = [:moo," C"," X",9]
    expected_result = {:moo=>[[1, 6], [2, 3], [4, 3]], " C"=>[[2, 2], [7, 1], [7, 5]], " X"=>[[5, 4]], 9=>[[3, 1], [3, 5], [6, 3]]}
    actual_result   = two_d(test_array, terms)
    assert_equal expected_result, actual_result
  end
end
